﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using llAma.Backend.Interface;

namespace llamaServer
{
    class llAmaCore 
    {
        const string gplNotice = "{0} v{3} Copyright (C) {1}  {2}\nThis program comes with ABSOLUTELY NO WARRANTY\nfor details please see the file COPYING.\nThis is free software, and you are welcome to redistribute it\nunder certain conditions; please see the file COPYING for more information";
        const string appCopyYear = "2011";
        const string appName = "llAmaServer";
        const string appVer = "0.1a";
        static string[] appDevelopers = { "Corey Thomasson", "Jason Couture" };
        const string appCopyright = "This program is licensed under the terms and conditions of the GNU General Public License v3 or later.";
        static void Main(string[] args)
        {
            Console.WriteLine(gplNotice, appName, appCopyYear, string.Join(", ", appDevelopers), appVer);
            Console.WriteLine("\n");

            Console.WriteLine("Starting llAma");
            ThreadPool.SetMaxThreads(150, 400);
            ThreadPool.SetMinThreads(16, 16);
            ConnectionFactory listener = new ConnectionFactory();
            listener.NewClientConnected += new EventHandler(listener_NewClientConnected);
            Console.WriteLine("\nllAma is up and running.");
            while (true)
            {
                System.Threading.Thread.Sleep(500);
                Console.Write("Total Clients Connected: {0}          \r", Backend.Implementation.TotalClients);
            }
        }
        //The code below, needs to become a part of the backend.
        static void listener_NewClientConnected(object sender, EventArgs e)
        {
            /*
            Connection client = (Connection)sender;
            client.Disconnecting += new EventHandler<ClientEventArgs>(client_Disconnecting);
            Console.WriteLine("New client from {0} has been assigned a UUID of {1}", client.RemoteEndPoint.Address.ToString(), client.UUID);
             */
            Backend.OnNewConnection((IConnection)sender);
        }
    }
}
